import Vue from 'vue'
import Router from 'vue-router'
import MainPage from '@/views/student/frame.vue'
import StudentIndex from '@/views/student/index/index.vue'
import AdminMainPage from '@/views/admin/mainPage'
import AdminIndex from '@/views/admin/control-pannel'
import AdminOrgMaintenance from '@/views/admin/org-maintenance/index'
import AdminOrgTeacher from '@/views/admin/org-maintenance/teacher'
import AdminOrgAdmin from '@/views/admin/org-maintenance/orgAdmin'
import AdminStudent from '@/views/admin/student-maintenance/index'
import AdminBaseGrade from '@/views/admin/base-config/grade'
import AdminBaseSubject from '@/views/admin/base-config/subject'
import AdminClasses from '@/views/admin/classes/class'
import AdminOnDemand from '@/views/admin/classes/on-demand'
import AdminSmallClass from '@/views/admin/classes/small-class'
import AdminSystemSettingsUsers from '@/views/admin/system-settings/users'
import AdminSystemSettingsRole from '@/views/admin/system-settings/role'
import AdminSystemSettingsPermission from '@/views/admin/system-settings/permission'
import AdminTeacherLabel from '@/views/admin/tags/teacher-label'
import AdminInstitutionLabel from '@/views/admin/tags/Institution-label'
import AdmincourseLabel from '@/views/admin/tags/course-label'
import AdminNewsList from '@/views/admin/news/news-list'
import AdminNotificationList from '@/views/admin/news/notification-list'
import AdminAdList from '@/views/admin/news/ad-list'
import StudentClasses from '@/views/student/ucenter/myClass'
import StudentOrders from '@/views/student/ucenter/myOrder'
import StudentSettings from '@/views/student/ucenter/settings'
// import StudentClassDetail from '@/views/student/class-detail'
import StudentOrderConfirm from '@/views/student/order/order-confirm'
import StudentOrderPayConfirm from '@/views/student/order/pay-method-confirm.vue'
import StudentLogin from '@/views/student/login/login.vue'
import StudentRegister from '@/views/student/register/register.vue'
import StudentLive from '@/views/student/watchLive/watch-live.vue'
import OrgPage from '@/views/org/orgPage'
import OrgIndex from '@/views/org/index/org-index'
import OrgTeacherList from '@/views/org/list/teacher-list'
import OrgStudentList from '@/views/org/list/student-list'
import OrgCourseList from '@/views/org/list/course-list'
import OrgSmallClass from '@/views/org/list/small-class'
import OrgOnDemand from '@/views/org/list/on-demand-list'
import OrgNotificationList from '@/views/org/list/notification-list'
import OrgNewsList from '@/views/org/list/news-list'
import OrgAdList from '@/views/org/list/ad-list'
import TeacherPage from '@/views/teacher/teacher-page'
import TeacherIndex from '@/views/teacher/list/teacher-index'
import TeacherStudent from '@/views/teacher/list/teacher-student'
import TeacherCourse from '@/views/teacher/list/teacher-course'
import TeacherSmallList from '@/views/teacher/list/small-class'
import TeacherOnDemand from '@/views/teacher/list/demand-list'
import TeacherData from '@/views/teacher/list/teacher-data'
import TeacherResetPwd from '@/views/teacher/list/teacher-resetPass'
import PlatformTeacher from '@/views/teacher/platform/teacher'
import PlatformOrg from '@/views/teacher/platform/org'
import PlatformOrgDttail from '@/views/teacher/platform/org-detail'
import PlatformCourseDetail from '@/views/teacher/platform/course-detail'
import PlatformTeacherDetail from '@/views/teacher/platform/teacher-detail'
import PlatformNews from '@/views/news-notice/news'
import PlatformNotice from '@/views/news-notice/notice'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: '_index',
      redirect: '/index',
      component: MainPage,
      children: [
        {
          path: '/index',
          name: 'index',
          meta: {
            title: '首页'
          },
          component: StudentIndex
        },
        {
          path: '/index/ucenter/myClass',
          name: 'myClass',
          meta: {
            title: '我的课程'
          },
          component: StudentClasses
        },
        {
          path: '/index/ucenter/myOrder',
          name: 'myOrder',
          meta: {
            title: '我的订单'
          },
          component: StudentOrders
        },
        {
          path: '/index/ucenter/settings',
          name: 'settings',
          meta: {
            title: '个人设置'
          },
          component: StudentSettings
        },
        // {
        //   path: '/index/class-detail',
        //   name: 'class-detail',
        //   component: StudentClassDetail
        // },
        {
          path: '/index/order-confirm',
          name: 'order-confirm',
          meta: {
            title: '提交订单'
          },
          component: StudentOrderConfirm
        },
        {
          path: '/index/pay-confirm',
          name: 'pay-confirm',
          meta: {
            title: '订单支付'
          },
          component: StudentOrderPayConfirm
        },
        {
          path: '/index/register',
          name: 'student-register',
          meta: {
            title: '注册'
          },
          component: StudentRegister
        },
        {
          path: '/index/teacher',
          name: 'platform-teacher',
          meta: {
            title: '老师风采'
          },
          component: PlatformTeacher
        },
        {
          path: '/index/org',
          name: 'platform-org',
          meta: {
            title: '机构风采'
          },
          component: PlatformOrg
        },
        {
          path: '/index/org-detail',
          name: 'org-detail',
          meta: {
            title: '机构详情'
          },
          component: PlatformOrgDttail
        },
        {
          path: '/index/news',
          name: 'news',
          meta: {
            title: '新闻'
          },
          component: PlatformNews
        },
        {
          path: '/index/notice',
          name: 'notice',
          meta: {
            title: '通知'
          },
          component: PlatformNotice
        },
        {
          path: '/index/course-detail',
          name: 'course-detail',
          meta: {
            title: '课程详情'
          },
          component: PlatformCourseDetail
        },
        {
          path: '/index/teacher-detail',
          name: 'teacher-detail',
          meta: {
            title: '老师详情'
          },
          component: PlatformTeacherDetail
        },
        {
          path: '/index/wacth-live',
          name: 'teacher-wacth-live',
          meta: {
            title: '课程学习'
          },
          component: StudentLive
        }
      ]
    },
    {
      path: '/index/login',
      name: 'student-login',
      component: StudentLogin
    },
    {
      path: '/admin',
      name: 'admin',
      redirect: '/admin/index',
      component: AdminMainPage,
      children: [
        {
          path: '/admin/index',
          name: 'admin_index',
          meta: {
            title: '首页',
            role: 'admin'
          },
          component: AdminIndex
        },
        {
          path: '/admin/org_maintenance',
          name: 'admin_org_maintenance',
          meta: {
            title: '机构列表',
            role: 'admin'
          },
          component: AdminOrgMaintenance
        },
        {
          path: '/admin/org_teacher',
          name: 'admin_org_teacher',
          meta: {
            title: '教师管理',
            role: 'admin'
          },
          component: AdminOrgTeacher
        },
        {
          path: '/admin/org_admin',
          name: 'admin_org_admin',
          meta: {
            title: '机构管理',
            role: 'admin'
          },
          component: AdminOrgAdmin
        },
        {
          path: '/admin/student',
          name: 'admin_student',
          meta: {
            title: '学生管理',
            role: 'admin'
          },
          component: AdminStudent
        },
        {
          path: '/admin/base_grade',
          name: 'admin_base_grade',
          meta: {
            role: 'admin'
          },
          component: AdminBaseGrade
        },
        {
          path: '/admin/base_subject',
          name: 'admin_base_subject',
          meta: {
            role: 'admin'
          },
          component: AdminBaseSubject
        },
        {
          path: '/admin/small-class',
          name: 'small_class',
          meta: {
            role: 'admin'
          },
          component: AdminSmallClass
        },
        {
          path: '/admin/classes',
          name: 'admin_classes',
          meta: {
            role: 'admin'
          },
          component: AdminClasses
        },
        {
          path: '/admin/on-demand',
          name: 'on-demand',
          meta: {
            role: 'admin'
          },
          component: AdminOnDemand
        },
        {
          path: '/admin/system/users',
          name: 'admin_sys_users',
          meta: {
            title: '系统设置',
            role: 'admin'
          },
          component: AdminSystemSettingsUsers
        },
        {
          path: '/admin/system/role',
          name: 'admin_sys_role',
          meta: {
            role: 'admin'
          },
          component: AdminSystemSettingsRole
        },
        {
          path: '/admin/system/permission',
          name: 'admin_sys_permission',
          meta: {
            role: 'admin'
          },
          component: AdminSystemSettingsPermission
        },
        {
          path: '/admin/tags/teacher-label',
          name: 'teacher-label',
          meta: {
            title: '老师标签',
            role: 'admin'
          },
          component: AdminTeacherLabel
        },
        {
          path: '/admin/tags/Institution-label',
          name: 'Institution-label',
          meta: {
            title: '机构标签',
            role: 'admin'
          },
          component: AdminInstitutionLabel
        },
        {
          path: '/admin/tags/course-label',
          name: 'course-label',
          meta: {
            title: '课程标签',
            role: 'admin'
          },
          component: AdmincourseLabel
        },
        {
          path: '/admin/news/news-list',
          name: 'news-list',
          meta: {
            title: '新闻列表',
            role: 'admin'
          },
          component: AdminNewsList
        },
        {
          path: '/admin/news/notification-list',
          name: 'notification-list',
          meta: {
            title: '通知列表',
            role: 'admin'
          },
          component: AdminNotificationList
        },
        {
          path: '/admin/news/ad-list',
          name: 'ad-list',
          meta: {
            title: '广告',
            role: 'admin'
          },
          component: AdminAdList
        },
        {
          path: '/admin/reset-pwd',
          meta: {
            title: '重置密码',
            role: 'admin'
          },
          component: TeacherResetPwd
        }
      ]
    },
    {
      path: '/org',
      name: 'org',
      redirect: '/org/index',
      component: OrgPage,
      children: [
        {
          path: '/org/index',
          name: 'org-index',
          meta: {
            title: '首页',
            role: 'org'
          },
          component: OrgIndex
        },
        {
          path: '/org/teacher-list',
          name: 'teacher-list',
          meta: {
            title: '老师列表',
            role: 'org'
          },
          component: OrgTeacherList
        },
        {
          path: '/org/student-list',
          name: 'student-list',
          meta: {
            title: '学生列表',
            role: 'org'
          },
          component: OrgStudentList
        },
        {
          path: '/org/small-class',
          name: 'org-small-class',
          meta: {
            title: '小班课',
            role: 'org'
          },
          component: OrgSmallClass
        },
        {
          path: '/org/course-list',
          name: 'course-list',
          meta: {
            title: '直播课',
            role: 'org'
          },
          component: OrgCourseList
        },
        {
          path: '/org/on-demand',
          name: 'on-demand-list',
          meta: {
            title: '点播课',
            role: 'org'
          },
          component: OrgOnDemand
        },
        {
          path: '/org/notification-list',
          name: 'org-notification-list',
          meta: {
            title: '通知列表',
            role: 'org'
          },
          component: OrgNotificationList
        },
        {
          path: '/org/news-list',
          meta: {
            title: '新闻列表',
            role: 'org'
          },
          name: 'org-news-list',
          component: OrgNewsList
        },
        {
          path: '/org/ad-list',
          meta: {
            title: '广告列表',
            role: 'org'
          },
          name: 'org-ad-list',
          component: OrgAdList
        },
        {
          path: '/org/reset-pwd',
          meta: {
            title: '重置密码',
            role: 'org'
          },
          component: TeacherResetPwd
        }
      ]
    },
    {
      path: '/teacher',
      name: 'teacher-page',
      redirect: '/teacher/index',
      component: TeacherPage,
      children: [
        {
          path: '/teacher/index',
          name: 'teacher-index',
          meta: {
            title: '首页',
            role: 'teacher'
          },
          component: TeacherIndex
        },
        {
          path: '/teacher/teacher-student',
          name: 'teacher-student',
          meta: {
            title: '学生',
            role: 'teacher'
          },
          component: TeacherStudent
        },
        {
          path: '/teacher/small-class',
          name: 'teacher-small-class',
          meta: {
            title: '小班课',
            role: 'teacher'
          },
          component: TeacherSmallList
        },
        {
          path: '/teacher/teacher-course',
          name: 'teacher-course',
          meta: {
            title: '直播课',
            role: 'teacher'
          },
          component: TeacherCourse
        },
        {
          path: '/teacher/on-demand',
          name: 'teacher-on-demand',
          meta: {
            title: '点播课',
            role: 'teacher'
          },
          component: TeacherOnDemand
        },
        {
          path: '/teacher/teacher-data',
          name: 'teacher-data',
          meta: {
            title: '老师详情',
            role: 'teacher'
          },
          component: TeacherData
        },
        {
          path: '/teacher/reset-pwd',
          meta: {
            title: '重置密码',
            role: 'teacher'
          },
          component: TeacherResetPwd
        }
      ]
    }
  ]
})

router.beforeEach((to, from, next) => {
  if (to.meta.role) {
    let role = localStorage.getItem('role')
    if (to.meta.role === role) {
      document.title = to.meta.title
      next()
    } else {
      next({
        path: '/index/login',
        query: {redirect: to.fullPath}
      })
    }
  } else {
    next()
  }
})

export default router
